<template>
	<uniEvaluate :list-data="listData" :goodsString="goodsString" :getCount="getCount">		
	</uniEvaluate>
</template>

<script>
	import uniEvaluate from '../../components/xiujun-evaluate/uni-evaluate.vue';
	export default {
	    components: {
			uniEvaluate
		},
		data(){
			return{
				//评论对象数组
				listData:[],
				//总条数
				getCount:0,
				//好评率
				goodsString:"",
				commodityid:0
			}
		},
		onLoad(options) {
			//获取商品id
			this.commodityid = options.commodityid;
			//接收总条数
			this.getCount = options.count;
			//接收好评率
			this.goodsString = options.goodsString;
			//获取全部评论
			this.getCommentAll(this.commodityid);
		},
		//下拉刷新函数
		onPullDownRefresh(){
			//清空数据，重新访问后台接口获取数据
			this.listData = [];
			this.getCommentAll(this.commodityid)
		},
		methods:{
			//获取商品全部评论，
			async getCommentAll(commodityid){
				this.listData = (await this.$api.reqGet({
					url:"/ygComment/commentAll?commodityId="+commodityid
				})).data;
				//将specifications规格详情解析成对象再转为字符串
				this.listData.forEach(item=>{
					item.picurls = eval(item.picurls);
				})
				this.listData.forEach(item=>{
					item.specifications = eval(item.specifications).toString();
				})
				// console.log(this.listData)
				//取消下拉标识
				uni.stopPullDownRefresh();
			},
			
			//由子组件调用，跳转至发表评论页面
			addComment(){
				uni.navigateTo({
					url:`../../pages/product/addComment?commodityid=`+this.commodityid
				})
			}
		}
	}
</script>

<style>

</style>
